﻿using System;
using Alfa.Math;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Alfa.Zproject.Test.Math {
	[TestClass]
	public class UnitTestFraction {
		public UnitTestFraction( ) { }

		Fraction a;
		Fraction b;

		#region Additional test attributes
		//
		// You can use the following additional attributes as you write your tests:
		//
		// Use ClassInitialize to run code before running the first test in the class
		// [ClassInitialize()]
		// public static void MyClassInitialize(TestContext testContext) { }
		//
		// Use ClassCleanup to run code after all tests in a class have run
		// [ClassCleanup()]
		// public static void MyClassCleanup() { }
		//
		/// <summary>
		/// Use TestInitialize to run code before running each test
		/// </summary>
		[TestInitialize( )]
		public void MyTestInitialize( ) {
			this.a = new Fraction(3, 5);
			this.b = new Fraction(1, 2);
		}

		/// <summary>
		/// Use TestCleanup to run code after each test has run
		/// </summary>
		[TestCleanup( )]
		public void MyTestCleanup( ) {
			this.a = null;
			this.b = null;
		}
		#endregion

		[TestMethod]
		public void Fraction_Negation( ) {
			Fraction x = -this.a;

			Assert.AreEqual(new Fraction(-3, 5), x);
		}

		[TestMethod]
		public void Fractions_Add( ) {
			Fraction x = this.a + this.b;

			Assert.AreEqual(new Fraction(11, 10), x);
		}

		[TestMethod]
		public void Fractions_Subtract( ) {
			Fraction x = this.a - this.b;

			Assert.AreEqual(new Fraction(1, 10), x);
		}

		[TestMethod]
		public void Fractions_Multiply( ) {
			Fraction x = this.a * this.b;

			Assert.AreEqual(new Fraction(3, 10), x);
		}

		[TestMethod]
		public void Fractions_Divide( ) {
			Fraction x = this.a / this.b;

			Assert.AreEqual(new Fraction(6, 5), x);
		}

		[TestMethod]
		public void Fraction_Add_Int( ) {
			Fraction x = this.a + 3;

			Assert.AreEqual(new Fraction(18, 5), x);
		}

		[TestMethod]
		public void Fraction_Subtract_Int( ) {
			Fraction x = this.a - 3;

			Assert.AreEqual(new Fraction(-12, 5), x);
		}

		[TestMethod]
		public void Fraction_Subtract_Int_Invert( ) {
			Fraction x = 3 - this.a;

			Assert.AreEqual(new Fraction(12, 5), x);
		}

		[TestMethod]
		public void Fraction_Multiply_Int( ) {
			Fraction x = this.a * 3;

			Assert.AreEqual(new Fraction(9, 5), x);
		}

		[TestMethod]
		public void Fraction_Divide_Int( ) {
			Fraction x = this.a / 3;

			Assert.AreEqual(new Fraction(3, 15), x);
			//Assert.AreEqual(new Fraction(1, 5), x);
		}

		[TestMethod]
		public void Fraction_Divide_Int_Invert( ) {
			Fraction x = 3 / this.a;

			Assert.AreEqual(new Fraction(15, 3), x);
			//Assert.AreEqual(new Fraction(30, 6), x);
			//Assert.AreEqual(new Fraction(5, 1), x);
			//Assert.AreEqual(new Fraction(5), x);
		}
	}
}
